home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / var / lib / dpkg / info / dash.postinst < prev    next >
Encoding:
Text File  |  2010-12-14  |  3.6 KB  |  144 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. # $1: dfile, $2: link target, $3: distrib
  5. replace_with_link() {
  6.     dfile=$1; ltarget=$2; distrib=$3
  7.     temp=$dfile.tmp
  8.     # Safely create a symlink to $ltarget at $dfile, first
  9.     # making a backup of $dfile (the file being diverted)
  10.     # in $distrib.
  11.     #
  12.     # The cp / ln -s / mv dance avoids having to live without
  13.     # $dfile (think: /bin/sh) for even a moment, so applications
  14.     # running in parallel can continue without trouble.
  15.     # See dash.preinst for details.
  16.     if [ -e "$dfile" ]; then
  17.         cp -dp "$dfile" "$distrib"
  18.     fi
  19.     ln -sf "$ltarget" "$temp"
  20.     mv -f "$temp" "$dfile"
  21. }
  22.  
  23. # $1: case, $2: dfile, $3: ltarget [, $4: distrib]
  24. check_divert() {
  25.     dfile=$2; ltarget=$3
  26.     distrib=${4:-$dfile.distrib}
  27.     diverter=$(dpkg-divert --listpackage $dfile)
  28.     truename=$(dpkg-divert --truename $dfile)
  29.     case "$1" in
  30.     true)
  31.         if [ "$diverter" != dash ]; then
  32.             # Let dpkg-divert error out; we are not taking
  33.             # over the diversion, unless we added it
  34.             # ourselves on behalf of bash.
  35.             if [ "$diverter" = bash ]; then
  36.                 dpkg-divert --package bash --remove $dfile
  37.             else
  38.                 dpkg-divert --package dash --remove $dfile
  39.                 # Make sure we die:
  40.                 echo "This should never be reached"
  41.                 exit 1
  42.             fi
  43.  
  44.             dpkg-divert --package dash --divert $distrib --add $dfile
  45.             # remove the old equivalent of $distrib, if it existed:
  46.             # or $dfile if there was no previous diversion! -- should never happen, unless preinst failed
  47.             if [ -n "$truename" ]; then
  48.                    rm -f "$truename"
  49.             fi
  50.             replace_with_link $dfile $ltarget $distrib
  51.         fi
  52.         ;;
  53.     false)
  54.         if [ "$diverter" = dash ]; then
  55.             # Simple hack. We also divert sh(1), remember?
  56.             bash=$(echo "$ltarget"|sed 's/dash/bash/')
  57.             dpkg-divert --package dash --remove $dfile
  58.             # The diversion is added as if we were bash, leaving
  59.             # no diversion would lead to a file conflict later
  60.             # when re-checked by dpkg
  61.             dpkg-divert --package bash --divert $distrib --add $dfile
  62.             # ugh? $truename should always be set (to $distrib)
  63.             if [ -n "$truename" ]; then
  64.                 rm -f "$truename"
  65.             fi
  66.             # Point everything back to bash
  67.             replace_with_link $dfile $bash $distrib
  68.         fi
  69.         ;;
  70.     ash)
  71.         # Code not modified by the NMU:
  72.         div=$(dpkg-divert --list $2)
  73.         case $div in
  74.         '')
  75.             ;;
  76.         *by\ ash)
  77.             dst=${div% by ash}
  78.             dst=${dst##* to }
  79.  
  80.             # Work around dpkg-divert bug.
  81.             if [ -e "$dst" ]; then
  82.                 mv "$dst" "$dst.dash-tmp"
  83.             fi
  84.             dpkg-divert --package ash --remove $2
  85.             if [ -e "$dst.dash-tmp" ]; then
  86.                 mv "$dst.dash-tmp" "$dst"
  87.             fi
  88.  
  89.             dpkg-divert --package dash --divert $distrib --add $2
  90.             if [ "$dst" != $distrib ] && [ -e "$dst" ]; then
  91.                 mv "$dst" $distrib
  92.             fi
  93.             ln -sf $3 $2.tmp
  94.             mv -f $2.tmp $2
  95.             ;;
  96.         *)
  97.             d=${2%/*}
  98.             if
  99.                 [ -h $2 ] && [ -f $2 ] && [ -f $d/$5 ] &&
  100.                 cmp $2 $d/$5
  101.             then
  102.                 ln -sf $3 $2.tmp
  103.                 mv -f $2.tmp $2
  104.             fi
  105.             ;;
  106.         esac
  107.     esac
  108. }
  109.  
  110. add_shell() {
  111.     if ! type add-shell > /dev/null 2>&1; then
  112.         return
  113.     fi
  114.  
  115.     add-shell /bin/dash
  116. }
  117.  
  118. debconf=
  119. if [ -f /usr/share/debconf/confmodule ]; then
  120.     . /usr/share/debconf/confmodule
  121.     debconf=yes
  122. fi
  123.  
  124. if [ "$1" = configure ] && [ -z "$2" ]; then
  125.     check_divert ash /bin/sh dash '' ash
  126.     check_divert ash /usr/share/man/man1/sh.1.gz dash.1.gz \
  127.         /usr/share/man/man1/sh.distrib.1.gz ash.1.gz
  128.     add_shell
  129. elif [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.4.18; then
  130.     add_shell
  131. fi
  132.  
  133. if [ $debconf ]; then
  134.     db_get dash/sh
  135.     check_divert "$RET" /bin/sh dash
  136.     check_divert "$RET" /usr/share/man/man1/sh.1.gz dash.1.gz \
  137.         /usr/share/man/man1/sh.distrib.1.gz
  138. fi
  139.  
  140. test "$1" = 'configure' || exit 0
  141. test -x /usr/bin/update-menus || exit 0
  142. test -z "$2" || dpkg --compare-versions "$2" lt 0.5.2-3 || exit 0
  143. exec update-menus
  144.